package com.yoda.mall.admin.controller;

import com.yoda.common.constant.RC;
import com.yoda.mall.admin.service.ProductService;
import com.yoda.mall.model.dto.ProductDetailDto;
import com.yoda.mall.model.dto.ProductDto;
import com.yoda.mall.model.entity.pms.Product;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.ProductDetailVo;
import com.yoda.mall.model.vo.R;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author shawn
 * @date 2022年 12月 17日 0:39
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @GetMapping("/list")
    public R productList(ProductDto dto) {
        PageResult<Product> pageResult = productService.selectByPage(dto);
        return R.success(pageResult);
    }

    @GetMapping("/simpleList")
    public R simpleQuery(){
return null;
    }
    @PostMapping("/update/{id}")
    public R updateProduct(@PathVariable Long id,@RequestBody ProductDetailDto productParam){
        productParam.setId(id);
        Integer count = productService.updateProduct(productParam);
        return R.success(count);
    }

    /**
     * 通过id查询产品详细信息
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/updateInfo/{id}")
    public R selectProductDetailById(@PathVariable Long id){
        ProductDetailVo vo = productService.selectProductDetailById(id);
        return R.success(vo);
    }

    /**
     * 创建产品
     *
     * @param productParam 产品参数
     * @return {@link R}
     */
    @PostMapping("/create")
    public R createProduct(@RequestBody ProductDetailDto productParam){
        Integer count = productService.createProduct(productParam);
        return R.success(count);
    }

    /**
     * 改变删除状态
     *
     * @param deleteStatus 删除状态
     * @param ids          id
     * @return {@link R}
     */
    @PostMapping("/update/deleteStatus")
    public R changeDeleteStatus(@RequestParam Integer deleteStatus,@RequestParam List<Long> ids){
        Integer count = productService.changeStatus(ids,deleteStatus, RC.DELETE_STATUS);
        return R.success(count);
    }

    /**
     * 改变新品状态
     *
     * @param newStatus 新品状态
     * @param ids          id
     * @return {@link R}
     */
    @PostMapping("/update/newStatus")
    public R changeNewStatus(@RequestParam Integer newStatus,@RequestParam List<Long> ids){
        Integer count = productService.changeStatus(ids,newStatus, RC.NEW_PRODUCT_STATUS);
        return R.success(count);
    }
    /**
     * 改变上架状态
     *
     * @param publishStatus 上架状态
     * @param ids          id
     * @return {@link R}
     */
    @PostMapping("/update/publishStatus")
    public R changePublishStatus(@RequestParam List<Long> ids,@RequestParam Integer publishStatus){
        Integer count = productService.changeStatus(ids,publishStatus, RC.SOLD_STATUS);
        return R.success(count);
    }

    /**
     * 改变推荐状态
     *
     * @param recommendStatus 推荐状态
     * @param ids          id
     * @return {@link R}
     */
    @PostMapping("/update/recommendStatus")
    public R changeRecommendStatus(@RequestParam Integer recommendStatus,@RequestParam List<Long> ids){
        Integer count = productService.changeStatus(ids,recommendStatus, RC.RECOMMEND_STATUS);
        return R.success(count);
    }

    /**
     * 改变审核状态
     *
     * @param verifyStatus 审核状态
     * @param ids          id
     * @return {@link R}
     */
    @PostMapping("/update/verifyStatus")
    public R changeVerifyStatus(@RequestParam Integer verifyStatus,@RequestParam List<Long> ids){
        Integer count = productService.changeStatus(ids,verifyStatus, RC.VERIFY_STATUS);
        return R.success(count);
    }

}
